package main.java.io;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;


public class io6 {

    public void buffer01() throws IOException {
        RandomAccessFile ra = new RandomAccessFile("C:\\Users\\86158\\Desktop\\datax.txt","rw");
        FileChannel channel = ra.getChannel();
        ByteBuffer bf = ByteBuffer.allocate(1024);

        //读
        int br = channel.read(bf);
        while (br != -1){
            bf.flip();
            while (bf.hasRemaining()){
                System.out.println((char) bf.get());
            }
            bf.clear();
            channel.read(bf);
        }
    }
}
